import 'package:flutter/material.dart';
import 'package:game123/pages/gamepages/dhhj.dart';
import 'package:game123/pages/gamepages/hhby.dart';
import 'package:game123/pages/gamepages/zcds.dart';
import 'package:game123/pages/gamepages/zlk.dart';

class Game extends StatefulWidget {
  @override
  GameState createState() => GameState();
}

class GameState extends State<Game> with SingleTickerProviderStateMixin {
  TabController _tabController;
  bool showFab = true;

  var _titles = ['航海霸业', '大航海家', '代号-HH', '航海霸业资料库'];
  final _pages = [Hhby(), Dhhj(), Zcds(), Zlk()];

  @override
  void initState() {
    super.initState();

    _tabController =
        TabController(vsync: this, initialIndex: 0, length: _titles.length);
    _tabController.addListener(() {
      if (_tabController.index == 1) {
        showFab = true;
      } else {
        showFab = false;
      }
      setState(() {});
    });
  }

  tabMaker() {
    List<Tab> tabs = [];
    for (var i = 0; i < _titles.length; i++) {
      tabs.add(Tab(
        text: _titles[i],
      ));
    }
    return tabs;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TabBar(
        controller: _tabController,
        indicatorColor: Colors.blue,
        labelColor: Colors.blue,
        // isScrollable: true,
        tabs: tabMaker(),
      ),

      body: TabBarView(
        controller: _tabController,
        children: _pages,
      ),

      // 悬浮按钮
      floatingActionButton: showFab
          ? FloatingActionButton(
              backgroundColor: Theme.of(context).accentColor,
              child: Icon(
                Icons.message,
                color: Colors.white,
              ),
              onPressed: () => print("open chats"),
            )
          : null,
    );
  }
}
